package com.wen.edu.controller;


import com.wen.commonutils.ResultEntity;
import com.wen.edu.entity.subject.OneSubject;
import com.wen.edu.service.EduSubjectService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author wen
 * @since 2021-05-29
 */
@RestController
@RequestMapping("/edu/service/subject")
public class EduSubjectController {
    @Resource
    private EduSubjectService eduSubjectService;

    /**
     * 添加课程分类，获取上传的文件，并读取文件内容
     *
     * @param file 上传后需要读取的excel文件
     * @return result of operation
     */
    @PostMapping("addSubject")
    public ResultEntity addSubject(MultipartFile file) {
        eduSubjectService.addSubject(file, eduSubjectService);
        return ResultEntity.ok();
    }

    /**
     * 查询课程列表并按照树形结构显示
     *
     * @return 所有的课程分类
     */
    @GetMapping("getAllSubject")
    public ResultEntity getAllSubject() {
        List<OneSubject> list = eduSubjectService.getAllSubject();
        return ResultEntity.ok().data("subjects", list);
    }
}

